package com.dp.tj;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//import org.hibernate.cfg.Configuration;
//import org.hibernate.SessionFactory;
public class getexcel extends HttpServlet
{
 
  public void init(ServletConfig config)
  {
  	/*try{
  		Configuration cf=new Configuration();
  		//cf.configure("E:\\resin-3.0.6\\deploy\\keer8\\hibernate1.cfg.xml");
  		 SessionFactory sf = cf.configure().buildSessionFactory();
  }catch(Exception e){e.printStackTrace();}
  	System.out.println("init");
  	*/
  	
  }
  public void doGet(HttpServletRequest req, HttpServletResponse res)   throws IOException, ServletException
  {   
     
      
  }
  public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
  {
  	//System.out.print("dsfgdf");
      req.setCharacterEncoding("GB2312");
  	HttpSession se=req.getSession();
  	String role=(String)se.getAttribute("role");
  	String userid=(String)se.getAttribute("user");
  	String jhh="";
  	String jxsx="";
  	if(role.equals("student"))
  	{
  	    jhh=(String)se.getAttribute("xsjhh");
  	    jxsx=(String)se.getAttribute("xsjxsx");
  	 }
  	else
  	{
  	    jhh=req.getParameter("jh");
  	 // new String(req.getParameter("jh");
  	    jxsx=req.getParameter("jxsx");	    
  	}
  	//System.out.println(role+"*"+userid);
  	 res.reset();
     res.setContentType("application/vnd.ms-excel");
     try
     {
         excelrw temp= new excelrw();
         temp.setJH(jhh,jxsx);
         //temp.writeExcel(res.getOutputStream());
     }catch(Exception e)
     {
         e.printStackTrace();
         req.setAttribute("exception",e);
     	RequestDispatcher dis=req.getRequestDispatcher("/public/view/error.jsp");    	 
     	dis.forward(req,res);
         
     }
  }
  public void doPost(HttpServletRequest req, HttpServletResponse res)  throws IOException, ServletException
  {
  	//doGet( req,  res);
//    res.setContentType("text/html ; charset=gb2312");
//    res.setHeader("Pragma", "no-cache");
//    PrintWriter out=res.getWriter();
//    try{ ctx = new InitialContext();
//    SessionFactory sf = (SessionFactory) ctx.lookup("hibernate/session_factory");
//    Session ss=sf.openSession();
//       }
    /*  System.out.println("sdfhgdfh");
      res.reset();
      res.setContentType("application/vnd.ms-excel");
      try{
      excelrw.writeExcel(res.getOutputStream());
      }catch(Exception e){e.printStackTrace();}
      System.out.println("end");
      */
     
  }
}


